<?php 
class Country_Model_Polloption extends Core_Model_Item_Abstract{
    
    public function getVoteCount($country_id){
        
        $voteT = Engine_Api::_()->getDbtable('pollvotes','country');
        $select = $voteT->select()
                        ->where('country_id = ?',$country_id)
                        ->where('polloption_id = ?',$this->polloption_id);
        $rows = $voteT->fetchAll($select);
        
        if ($rows) return count($rows);
        return 0;
    }
    
    public function setVote($user_id,$country_id){
        $voteT = Engine_Api::_()->getDbtable('pollvotes','country');
        $vote = $voteT->createRow();
        $vote->user_id = $user_id;
        $vote->country_id = $country_id;
        $vote->polloption_id = $this->polloption_id;
        $vote->poll_id = $this->poll_id;
        $vote->save();
    }
    
    public function getValue($country_id){
        $voteT = Engine_Api::_()->getDbtable('pollvotes','country');
        $select = $voteT->select()
                        ->where('country_id = ?',$country_id)
                        ->where('polloption_id = ?',$this->polloption_id);
        $row = $voteT->fetchRow($select);
        
        if ($row) return $row->value;
        return '';
    }                
  
}
?>